package com.Hsu.demo;

import com.Hsu.demo.component.UserComponent;
import com.Hsu.demo.config.UserConfig;
import com.Hsu.demo.config.UserInfo;
import com.Hsu.demo.controller.UserController;
import com.Hsu.demo.repo.UserRepository;
import com.Hsu.demo.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        //Spring上下文，返回的就是Spring的运行环境
        ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        //从Spring上下⽂中获取对象
        UserController bean = context.getBean(UserController.class);
        //使用对象
        bean.doController();


        //UserService userService = context.getBean(UserService.class);
        //userService.doService();
        ////根据名称获取bean
        //UserService userService2 = (UserService)context.getBean("userService");
        //userService2.doService();
        ////根据名称和类型获取bean
        //UserService userService3 = context.getBean("userService", UserService.class);
        //userService3.doService();
        //
        //UserRepository userRepository = context.getBean(UserRepository.class);
        //userRepository.doRepository();
        //
        //UserComponent userComponent=context.getBean(UserComponent.class);
        //userComponent.doComponent();
        //
        //UserConfig userConfig=context.getBean(UserConfig.class);
        ////userConfig.doConfig();
        //System.out.println("userConfig:"+userConfig);
        //
        //UserConfig userConfig2=context.getBean(UserConfig.class);
        //System.out.println("userConfig2:"+userConfig2);
        //System.out.println("userConfig==userConfig2:"+ (userConfig==userConfig2));
        //
        ////@Bean演示
        //UserInfo userInfo=(UserInfo) context.getBean("userInfo");
        //System.out.println(userInfo);
        //UserInfo userInfo2=(UserInfo) context.getBean("userInfo2");
        //System.out.println(userInfo2);


    }

}
